package com.sansi.pencilbook.mapper;

import com.sansi.pencilbook.entity.UserBook;
import org.apache.ibatis.annotations.*;

import java.sql.SQLException;
import java.util.List;

/**
 * 功能说明: 用户行为的增删改查
 *
 * @author lsy13
 */
@Mapper
public interface UserBookMapper {

    @Select("select id, user_id, isbn, behavior, time from user_book")
    public List<UserBook> findAll() throws SQLException;

    @Select("select id, user_id, isbn, behavior, time from user_book where user_id=#{userId}")
    public List<UserBook> findByUser(int userId) throws SQLException;

    @Select("select id, user_id, isbn, behavior, time from user_book where behavior=#{behavior}")
    public List<UserBook> findByBehavior(String behavior) throws SQLException;

    @Select("select id, user_id, isbn, behavior, time from user_book where behavior=#{behavior} and user_id=#{userId}")
    public List<UserBook> findByUserBehavior(int userId, String behavior) throws SQLException;

    @Select("select id, user_id, isbn, behavior, time from user_book where isbn=#{isbn} and user_id=#{userId}")
    public List<UserBook> findByUserBook(int userId, String isbn) throws SQLException;

    @Select("select id, user_id, isbn, behavior, time from user_book where isbn=#{isbn} and behavior=#{behavior} and user_id=#{userId}")
    public List<UserBook> findByUserBookBehavior(int userId, String isbn, String behavior) throws SQLException;

    @Select("select id, user_id, isbn, behavior, time from user_book where isbn=#{isbn}")
    public List<UserBook> findByBook(String isbn) throws SQLException;

    @Insert("insert into user_book (user_id, isbn, behavior, time) values(#{userId},#{isbn},#{behavior},#{time})")
    public int saveUserBook(UserBook userBook) throws SQLException;

    @Delete("delete from user_book where id=#{id}")
    public int deleteUserBook(UserBook userBook) throws SQLException;
}
